/*
getters 基于state的getter属性
 */
export default {
    getCategorys (state) {
        let {categorys} = state;
        let arr =[];
        categorys.forEach((item , index) => {
            let num =Math.floor(index/8);
            if(!arr[num]){
                arr[num]=[];
            }
            arr[num].push(item);
        })
        console.log(arr)
        return arr;
    },
    totalCount (state){
      return state.shopCar.reduce((preTotal,food) => {
        return preTotal+food.count
      },0);
    },
    totalPrice (state) {
      return state.shopCar.reduce((preTotal,food) => {
        return preTotal+food.count*food.price
      },0);
    },
    positive (state) {  //商家评论的好的评论 的number
        return state.shopRatings.reduce((preTotal,rating) => {
            return preTotal+(rating.rateType==0?1:0)
        },0);
    }
}
